package exception;

public class Demo05 {
    public static void main(String[] args) throws Exception {
        Person person = new Person();
        person.setAge(-17);
        System.out.println(person.getAge());
    }
}
class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception {
        if (age > 0 && age < 100) {
            this.name = name;
        }else {
            throw new Exception("年龄非法");
        }
    }
}
